package com.mark.web.data.controller.portal;

import com.mark.common.CurrentUser;
import com.mark.common.ServerResponse;
import com.mark.web.data.entity.po.Seller;
import com.mark.web.data.service.ISellerService;
import com.mark.web.data.util.CookieUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 卖家信息管理控制器
 * @Author: Mark
 * @CreateDate: 2018/8/14.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */

@RestController
@RequestMapping("/seller/")
public class SellerController {
    @Autowired
    private ISellerService iSellerService;


    //1.用户注册
    @PostMapping(value = "register.do")
    public ServerResponse<String> register(Seller seller, HttpServletRequest httpServletRequest)  {
        String loginToken = CookieUtil.readLoginToken(httpServletRequest);
        if(seller == null ){
            return ServerResponse.createByIllegalArgument("店家注册信息不能为空");
        }
        // TODO: 2019/1/20
        /*User currentUser = (User) response.getData();
        if(currentUser.getRole() == UserStateEnum.SELLER_CUSTOMER.getRole()){
            return ServerResponse.createByErrorMessage("你已经注册成为店家了！请勿重复操作");
        }*/
        seller.setUserId(CurrentUser.getCurrentUserId());
        return  iSellerService.register(seller,loginToken);
    }
}
